#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);
    // 隐藏按钮的效果，只显示本地按钮
    ui->lineBox->hide();
    // 创建line动画效果
    //设置line1的动画效果
    animationLine1 = new QPropertyAnimation(ui->line1, "geometry", this);
    animationLine1->setDuration(1500);
    animationLine1->setKeyValueAt(0, QRect(5, 26, 3, 0));
    animationLine1->setKeyValueAt(0.5, QRect(5, 9, 3, 17));
    animationLine1->setKeyValueAt(1, QRect(5, 26, 3, 0));
    animationLine1->setLoopCount(-1);  // 无限循环
    animationLine1->start();
    // 其他line动画效果
    animationLine2 = new QPropertyAnimation(ui->line2, "geometry", this);
    animationLine2->setDuration(1600);
    animationLine2->setKeyValueAt(0, QRect(12, 26, 3, 0));
    animationLine2->setKeyValueAt(0.5, QRect(12, 9, 3, 17));
    animationLine2->setKeyValueAt(1, QRect(12, 26, 3, 0));
    animationLine2->setLoopCount(-1);  // 无限循环
    animationLine2->start();

    animationLine3 = new QPropertyAnimation(ui->line3, "geometry", this);
    animationLine3->setDuration(1700);
    animationLine3->setKeyValueAt(0, QRect(19, 26, 3, 0));
    animationLine3->setKeyValueAt(0.5, QRect(19, 9, 3, 17));
    animationLine3->setKeyValueAt(1, QRect(19, 26, 3, 0));
    animationLine3->setLoopCount(-1);  // 无限循环
    animationLine3->start();

    animationLine4 = new QPropertyAnimation(ui->line4, "geometry", this);
    animationLine4->setDuration(1800);
    animationLine4->setKeyValueAt(0, QRect(26, 26, 3, 0));
    animationLine4->setKeyValueAt(0.5, QRect(26, 9, 3, 17));
    animationLine4->setKeyValueAt(1, QRect(26, 26, 3, 0));
    animationLine4->setLoopCount(-1);  // 无限循环
    animationLine4->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndText(const QString &btIcon, const QString &btText, int mid)
{
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->pageId = mid;
}

void BtForm::clearBackground()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color: #D8D8D8;}");
}

int BtForm::getPageId()
{
    return pageId;
}

void BtForm::showAnimation(bool isShow)
{
    if (isShow)
    {
        ui->lineBox->show();
    }
    else
    {
        ui->lineBox->hide();
    }
}


void BtForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    // 按钮按下改变背景颜色
    ui->btStyle->setStyleSheet("#btStyle{ background-color: rgb(30, 206, 154);}");
    // 切换bodyright的页面
    emit btClick(pageId);
}
